import type { Slide } from '@/types/slides'
import { GetTemplateItemData } from './checkTemplate'
import { nanoid } from 'nanoid'

/**
 * @name 生成一段文本的幻灯片
 * @param tempId 模板ID
 * @param params 
 * @returns 
 */
export async function GetOnlyTextContCourseware(tempId: string, params: PPTManyTxtDataSchema): Promise<Slide | undefined> {
  const tempData = await GetTemplateItemData(tempId, 'text')
  if (!tempData) return

  let strSlide = JSON.stringify(tempData.default)

  strSlide = strSlide.replace('%幻灯片段落%', params.txt.join(''))
  strSlide = strSlide.replace('%幻灯片章节%', params.group)

  const slideData = JSON.parse(strSlide)

  slideData.id = nanoid(10)
  slideData.elements.forEach((el: any) => {
    el.id = nanoid(10)
  })
  
  return slideData
}
